Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Javascript "multidimensional" array behaving differently based on location in script

I've created a "multidimensional" JS array with a function. Within that function, the console log shows the array with all elements as I would expect it.

Outside of the function, I can still show the array in the console, but it looks different, and I can't access elements with the typical arr[0] identifiers.

Any ideas what might be going on? I need to be able to access this array globally. Please be patient with me, I'm new and green.

var thisQsetTrue = [];
var thisQsetFalse = [];
//Start getDoc
function getDoc() {
    const xhttp = new XMLHttpRequest();
    xhttp.onload = function() {
        buildArray(this);
    }
    xhttp.open("GET", "AddisonNovice.xml");
    xhttp.send();
}
//End get Doc
//Start buildArray
function buildArray(xml) {
    const xmlDoc2 = xml.responseXML;
    const y = xmlDoc2.getElementsByTagName("question");
    //Build the true answer array
    for (let i = 0; i <y.length; i++) {
        var tempArray = [];
        if (y[i].getElementsByTagName("type")[0].childNodes[0].nodeValue == "true") {
            tempArray.push(y[i].getElementsByTagName("query")[0].childNodes[0].nodeValue);
            tempArray.push(y[i].getElementsByTagName("feedback")[0].childNodes[0].nodeValue);
            thisQsetTrue.push(tempArray);
        }
    }
    //Build the false answer array
    for (let i = 0; i <y.length; i++) {
        var tempArray2 = [];
        if (y[i].getElementsByTagName("type")[0].childNodes[0].nodeValue == "false") {
            tempArray2.push(y[i].getElementsByTagName("query")[0].childNodes[0].nodeValue);
            tempArray2.push(y[i].getElementsByTagName("feedback")[0].childNodes[0].nodeValue);
            thisQsetFalse.push(tempArray2);
        }
    }
    console.log(thisQsetFalse);//Array displays normally
}
//End buildArray
//Call getDoc
getDoc();
console.log(thisQsetFalse);//Array displays differently

Console log screenshot. As you can see, all the elements of the array are there, but it looks different, and I can't get to the elements: Screenshot of console log

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!